﻿//#include <iostream> // std::cout
//#include <chrono> // std::chrono::milliseconds
//#include <thread> // std::thread
//#include <mutex> // std::timed_mutex
//std::timed_mutex mtx;
//void fireworks(int i)
//{
//	//std::cout << i;
//	// waiting to get a lock: each thread prints "-" every 200ms:
//	while (!mtx.try_lock_for(std::chrono::milliseconds(1000)))
//	{
//		std::cout << "-";
//	}
//	std::cout << i;
//	// got a lock! - wait for 1s, then this thread prints "*"
//	std::this_thread::sleep_for(std::chrono::milliseconds(5000));
//	std::cout << "*\n";
//	mtx.unlock();
//}
//int main()
//{
//	std::thread threads[2];
//	// 利⽤移动赋值的⽅式，将创建的临时对象(右值对象)移动赋值给创建好的空线程对象 
//	for (int i = 0; i < 2; ++i)
//		threads[i] = std::thread(fireworks, i);
//	for (auto& th : threads)
//		th.join();
//	return 0;
//}